package main

import "fmt"

type People struct {
	time string
}

func (p People) PrintInfo() {
	fmt.Println("people:", p.time)
}

type Student struct {
	People
	Name string
	Age  int
}
type Student2 struct {
	*People
	Name string
	Age  int
}

func (s Student) Info() {
	s.People.PrintInfo()
	fmt.Printf("name:%s,age:%d\n", s.Name, s.Age)
}

func (s Student2) Info() {
	s.People.PrintInfo() //结构体指针调用方法自动解引用
	fmt.Printf("name:%s,age:%d\n", s.Name, s.Age)
}

func main() {
	p := People{time: "2002-02-24 15:24:34"}
	s := Student{
		People: p,
		Name:   "枫枫",
		Age:    21,
	}
	s2 := Student2{
		People: &p,
		Name:   "枫枫",
		Age:    21,
	}
	fmt.Printf("p:%p,s.People:%p\n", &p, &s.People)
	fmt.Printf("p:%p,s2.People:%p\n", &p, s2.People)
	s.Info()
	s2.Info()
	//无论是值传递还是引用传递都可以调用父类的方法和属性。
	s.PrintInfo()
	s2.PrintInfo()
	fmt.Printf("s.time: %v\n", s.time)
}
